package controllerlayer;

import java.util.ArrayList;

import modellayer.Company;
import modellayer.KeyPerson;
import modellayer.Note;
import dblayer.NoteDB;

/**
 * The AppointmentCtrl class to handle apppointment information
 * 
 * @author Allan Eriksen, Andreas Rye, Casper Madsen, Christian Stidsborg,
 *         Stefan Bols
 */

public class NoteCtrl {
	private NoteDB noteDB;
	private KeyPersonCtrl kpCtrl;
	private ZipCodeCtrl zcCtrl;

	/**
	 * @param appointmentDB
	 * @param kpCtrl
	 * @param zcCtrl
	 */

	/**
	 * Constructor for the appointmentCtrl
	 */
	public NoteCtrl() {
		noteDB = new NoteDB();
		kpCtrl = new KeyPersonCtrl();
		zcCtrl = new ZipCodeCtrl();
	}

	/**
	 * Method used to create an appointment object and puts further to
	 * appointmentDB which will insert it into the Database. If failure, this
	 * method throws an exception.
	 * 
	 * 	
	 * @param subject
	 * @param fromDate
	 * @param toDate
	 * @param address
	 * @param zip
	 * @param addedDate
	 * @param kp
	 * @return success
	 */
	public boolean createNote(String noteTitle, String noteText, long addedDate, KeyPerson kp, Company c) {
		boolean success = false;

		Note n = new Note(-1, noteTitle, noteText, addedDate);
		n.setCompany(c);
		n.setKeyPerson(kp);

		try {
			if (noteDB.insertNote(n) != -1) {
				success = true;
			}
		} catch (Exception e) {
			System.out
					.println("Failed to insert Note into database! (NoteCtrl) Error: " + e);
		}

		return success;
	}

	/**
	 * Method used to return all objects in the appointment ArrayList since
	 * wClause is null
	 * 
	 * @return appointmentDB.getAppointments()
	 */
	public ArrayList<Note> getAllNotes() {
		return noteDB.getNotes(null);
	}

	 public boolean deleteNote(int noteId) throws Exception {
		 return noteDB.deleteNote(noteId);
	 }
	 
	 public Note findNote(int noteId) {
		 return noteDB.findNote(" noteId="+noteId);
	 }

}
